<?php
/**
 * This page handles the creation of new projects, using AJAX Quite heavily.
 * Found at /add/project
 * 
 * This page can only be accessed using mod_rewrite.
 */

    require_once('../SiteIncludes.GLOBAL.php');
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	$gVAR['e'] = '404';
	require_once('error_handler.php');
    }
    
    if(isset($_LOGGEDINUSER) === true && $_LOGGEDINUSER !== false) {
	/**
	* We are on an editing page, so we will add the timeout warning js 
	* & add the tooltip manager
	*/
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/inactivityWarning.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript">inactivity_hour();</script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ToolTip.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ajaxCleanup.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ajaxConfirmer.js"></script>');
	$TemplateEngine->add_preloadScript('<script type="text/javascript" src="/js/EMDE.js"></script>');
	
	/**
	 * Javascript For this page 
	 */
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/NewProject.js"></script>');
	
	$central_check_unit = <<<EOCHECKUNIT
	    <div class="row-fluid" id="check_container">
		<div class="span4" style="text-align: left;"><h2><img src="/img/not_ok.png" id="img_check_status" style="width: 24px; height: 24px;" alt="Status" /> 1. Check Short Name</h2></div>
		<div class="span8">
		    <iframe src="" id="x_frame_check_project" name="x_frame_check_project" style="height: 0px; width: 0px; display: none; visibility: hidden;"></iframe>
		    <form action="/edjx/addproject/check" method="POST" target="x_frame_check_project" id="check_form">
			<input type="text" name="ib_text_nametocheck" id="ib_text_nametocheck" />
			<!-- move this seven pixels up because it doesnt line up! -->
			<input type="submit" value="Check" style="margin-top: -7px!IMPORTANT;" id="submit_check" />&nbsp;
			<span class="errorStyle hiddenElement" id="err_check"></span>
		    </form>
		</div>
	    </div>
EOCHECKUNIT;
	$central_add_unit = <<<EOADDUNIT
	    <div class="row-fluid" id="add_container" style="visibility: hidden; display: none;">
		<div class="span4" style="text-align: left;"><h2><img src="/img/not_ok.png" id="img_check_status" style="width: 24px; height: 24px;" alt="Status" /> 2. Setup Project</h2></div>
		<div class="span8">
		    <iframe src="" id="x_frame_add_project" name="x_frame_add_project" style="height: 0px; width: 0px; display: none; visibility: hidden;"></iframe>
		    <form action="/edjx/addproject/add" method="POST" target="x_frame_add_project" id="check_form">
		    <input type="hidden" name="hidden_text_alias" id="hidden_text_alias" value="" />
			<div class="row-fluid">
			    <div class="span4">
				<h3>Name&nbsp;:</h3>Chars. Left: <span id="add_name_count">128</span>
			    </div>
			    <div class="span8">
				<input type="text" name="add_name" id="add_name" style="width: 100%;" onkeyup="NewProject.addnamecheck();" onchange"NewProject.addnamecheck();" />
			    </div>
			</div>
			<div class="row-fluid">
			    <div class="span4"><h3>Description&nbsp;:</h3></div>
			    <div class="span8"><textarea name="add_desc" id="add_desc" style="width: 100%; height: 75px;" onkeyup="NewProject.adddesccheck();" onchange"NewProject.adddesccheck();"></textarea></div>
			</div>
			<div class="row-fluid">
			    <div class="span4">&nbsp;</div>
			    <div class="span8">
				<input type="submit" value="Add Project" id="add_submit" disabled="disabled" />&nbsp;
				<span class="errorStyle hiddenElement" id="err_add"></span>
			    </div>
			</div>
		    </form>
		</div>
	    </div>
EOADDUNIT;
	$central_done_unit = <<<EODONEUNIT
	    <div class="row-fluid" id="done_container" style="visibility: hidden; display: none;">
		<div class="row-fluid">
		    <div class="span12" style="text-align: center;">
			<h2>Success!</h2>
			<button type="button" onclick="NewProject.navigate();">Go to Edit Page</button>
		    </div>
		</div>
	    </div>
EODONEUNIT;
	$TemplateEngine->create_content_html($central_check_unit);
	$TemplateEngine->create_content_html($central_add_unit);
	$TemplateEngine->create_content_html($central_done_unit);
	
	
	/************************************************************
	 * 
	 * Right Hand Side Box HTML 
	 * 
	 ***********************************************************/
	$sidebox_html = <<<EOA
	    Steps to making a project:<br />
		<ul>
		    <li>1. Check your shortname exists.</li>
		    <li>2. Setup the initial project with a name and description.</li>
		    <li>3. Your setup! Now you can add tags, contributors and more!</li>
		    <li><span style="font-style: italic;">Hint:</span> Your project will initially be hidden, so you can set it up properly. Unhide it to allow people to find it using its tags!</li>
		</ul>
EOA;
	$TemplateEngine->create_sidebar_html(
		    $Templater->createSidebarItem('Creating a new project is simple!', $sidebox_html)
		);
	$TemplateEngine->render();
    } else {
	$gVAR['e'] = '404';
	require_once('error_handler.php');
    }
?>
